export {};

class Person {
  // 属性声明
  name: string;
  age: number;

  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }

  introduce(): void {
    console.log(`我是${this.name} ，我今年${this.age}`);
  }
}

//类的继承
class Student extends Person {
  grade: string;
  constructor(name: string, age: number, grade: string) {
    //调用父类的构造器
    super(name, age);
    this.grade = grade;
  }

  //重写 覆盖 父类的方法， override 标记 此方法是从父类中继承的， 如果方法签名不正确，会有验证
  override introduce(): void {
    console.log(`我是${this.name} ，我今年${this.age}， 现在${this.grade}`);
  }

  learn() {
    console.log(`${this.name}在学习`);
  }
}

let p1: Person = new Person("张飞", 18);
p1.introduce();

let stu1: Student = new Student("刘备", 19, "大三");
stu1.introduce();
stu1.learn();
